package w83b.w83bOperacionesPaso.w83bComunicaciones;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import es.ejie.frmk.presentacion.operacion.paso.Q70ActionPasoOP;
import es.ejie.frmk.presentacion.sesiondatos.Q70ContextoEJIE;

public class W83bPartirEnvioComunicacionAction extends Q70ActionPasoOP{


	
	protected void processOP(Q70ContextoEJIE contexto, ActionErrors errores, ActionMapping mapping,
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		
	}

	protected ActionForward processForward(Q70ContextoEJIE contexto, ActionErrors errors, ActionMapping mapping, 
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		HashMap generarRtf = (HashMap)contexto.get("generarRtf");
		List comunicindCtx = (ArrayList)contexto.get("w83bListaInd");
		String tamanyoCtx = (String)contexto.get("tamParcial");
		
		if(StringUtils.isEmpty(tamanyoCtx)){
			tamanyoCtx = "0";
		}
		
		if(!tamanyoCtx.equals(String.valueOf(comunicindCtx.size()))){
			int tamanyoRestante = comunicindCtx.size() - Integer.parseInt(tamanyoCtx);
			
			if(tamanyoRestante>=100){
				tamanyoRestante = 100;
			}
			
			List listaParcial = comunicindCtx.subList(Integer.parseInt(tamanyoCtx),Integer.parseInt(tamanyoCtx)+tamanyoRestante);
			contexto.set("tamParcial", String.valueOf(Integer.parseInt(tamanyoCtx)+tamanyoRestante));
			generarRtf.put("comunicind",listaParcial);
			contexto.set("generarRtf",generarRtf);
			return mapping.findForward("oi");			
		}else{
			contexto.set("tamParcial","0");
			return mapping.findForward("ok");			
		}
		
		
		

		
	}
	
		
}

